package cc.bluemc.modules.adminuserExtend.action;

import cc.bluemc.modules.adminUser.entity.AdminUser;
import cc.bluemc.modules.adminuserExtend.entity.AdminuserExtendEntity;
import cc.bluemc.modules.adminuserExtend.service.AdminuserExtendService;
import cc.bluemc.platform.comm.ActionResultMap;
import cc.bluemc.platform.comm.BaseAction;
import cc.bluemc.platform.comm.DataTablesPagination;
import cc.bluemc.platform.jdbctemplatetool.exception.NoColumnAnnotationFoundException;
import cc.bluemc.platform.jdbctemplatetool.exception.NoIdAnnotationFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/adminuserExtend")
public class AdminuserExtendAction extends BaseAction{
	@Autowired
	private AdminuserExtendService adminuserExtendService;
	/*
	*表单页面
	*/
	@RequestMapping("form")
	public String addForm(Integer id,Model model) throws NoIdAnnotationFoundException, NoColumnAnnotationFoundException{
		if(null!=id){
			AdminuserExtendEntity adminuserExtend= adminuserExtendService.get(id);
			model.addAttribute("bean", adminuserExtend);
		}
		return "adminuserExtend/form";
	}
	/*
	*保存
	*/
	@RequestMapping("save")
	public String save(AdminuserExtendEntity adminuserExtend,Model model){
		try {
			AdminUser adminUser = getAdminUser();
			adminuserExtend.setUserid(adminUser.getId());
			adminuserExtendService.saveOrUpdate(adminuserExtend);
			resultMap.setSuccess(true);
		} catch (Exception e) {
			resultMap.setSuccess(false);
			resultMap.setMsg("保存失败");
		}
		return "redirect:list";
	}
	/**
	 * 列表页面
	 * @param model
	 * @return
	 */
	@RequestMapping("list")
	public String list(Model model){
		/*
		resultMap.setSuccess(true);
		List<AdminuserExtendEntity> list = adminuserExtendService.getAll();
		resultMap.setData(list);
		model.addAttribute(_RESULTMAP,resultMap);
		*/
		return "adminuserExtend/list";
	}
	/**
	 * 分布查询数据
	 * @param page
	 * @return
	 */
	@ResponseBody
	@RequestMapping("pageList")
	public DataTablesPagination listPage(DataTablesPagination page,HttpServletRequest request){
		AdminuserExtendEntity adminuserExtend = new AdminuserExtendEntity();
		
		adminuserExtendService.getListOfPage(page,adminuserExtend );
		return page;
	}
	/**
	 * 删除
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("del")
	public ActionResultMap del(AdminuserExtendEntity adminuserExtend) throws Exception{
		adminuserExtendService.delete(adminuserExtend);
		resultMap.setMsg("删除成功！");
		return resultMap;
	}
}
